package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.AdminRedPacketRuleUpdateByIdDTO;
import com.sc.nft.entity.dto.AdminRedPakcetRuleAddDTO;
import com.sc.nft.entity.vo.AdminRedPacketRuleFindPageVO;
import com.sc.nft.service.RedPacketRuleService;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "红包规则配置")
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/admin/redPacketRule")
public class RedPacketRuleController {

    private final RedPacketRuleService redPacketRuleService;




    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增规则", notes = "新增规则", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result add(@RequestBody AdminRedPakcetRuleAddDTO adminRedPakcetRuleAddDTO) {
        redPacketRuleService.add(adminRedPakcetRuleAddDTO);
        return Result.success();
    }


    @PostMapping(value = "/findPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查看数据列表", notes = "查看数据列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminRedPacketRuleFindPageVO> findPage(@RequestBody PageRequest pageRequest) {
        Page<AdminRedPacketRuleFindPageVO> page = redPacketRuleService.findPage(pageRequest);
        return PageResult.success(page);
    }

    @PostMapping(value = "/updateById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "编辑", notes = "编辑", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateById(@RequestBody AdminRedPacketRuleUpdateByIdDTO adminRedPacketRuleUpdateByIdDTO) {
      redPacketRuleService.updateById(adminRedPacketRuleUpdateByIdDTO);
        return Result.success();
    }
}
